import { Component, OnInit ,Input} from '@angular/core';
import {Router,ActivatedRoute} from  '@angular/router';
import {RollService} from "../../../../../my-service/roll.service";
import { NzMessageService } from 'ng-zorro-antd';

@Component({
  selector: 'app-roll-nav',
  templateUrl: './roll-nav.component.html',
  styleUrls: ['./roll-nav.component.css'],
})
export class RollNavComponent implements OnInit {
  @Input() classGuid:string;
  classInfo={
    ClassName:'',
  };
  routerIndex=0;//导航条当前所在位置
  constructor(private route: Router,private routeInfo:ActivatedRoute,private rollServe:RollService,private msg:NzMessageService) {
  }
 getClassInfo() {
    this.rollServe.getClassInfo(this.classGuid).then(res=>{
      if (res.status == 1){
        this.classInfo = res.data[0];
      }else {
        console.log(res);
        this.msg.error('服务器内部错误请刷新重试');
      }
    })
 }
  ngOnInit() {
    this.getRouterIndex();
    this.getClassInfo();
  }
  goToNotice(index) {
    this.routerIndex = index;
  this.route.navigate([`home/index/class/info/${this.classGuid}/notice`,this.classGuid]);//路由到公告
  }
  goClassIndex(index){
    this.routerIndex = index;
    this.route.navigate(['home/index/class/info',this.classGuid]);//路由到主页
  }
  goToSetting(index) {
    this.routerIndex = index;
    this.route.navigate([`home/index/class/info/${this.classGuid}/setting`,{id:this.classGuid}]);//路由到设置
  }
  goToStart() {
    this.route.navigate(['home/index/class']);
  }
  getRouterIndex () {
    if(/info\/setting/g.test(location.href)){
      this.routerIndex = 2;
    }else if (/home\/info\/[^!]{36}\/notice/g.test(location.href)){
      this.routerIndex = 1;
    }else {
      this.routerIndex = 0;
    }
  }/*导航条和当前所在路由对应*/

}
